package com.linkstec.queue;
import java.text.DecimalFormat;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

/**
 * @Author：sks
 * @Description：
 * @Date：Created in 10:39 2018/1/11
 * @Modified by：
 **/

//二维平面上一个点
 class point {
    //坐标x
    double x;

    //坐标y
    double y;
    public point(double x, double y){
        this.x = x;
        this.y = y;
    }
}

class PointComparator {
    private   point pointOne;
    private point pointTwo;
    public double distance;
    public PointComparator(point pointOne,point pointTwo)
    {
        this.pointOne = pointOne;
        this.pointTwo = pointTwo;
        computeDistance();
    }
    //计算两点之间距离
    private void computeDistance() {
        double val = Math.pow((this.pointOne.x - this.pointTwo.x),2) +
                Math.pow((this.pointOne.y - this.pointTwo.y),2);
        this.distance = Math.sqrt(val);
    }


}
public class PriorityQueuep_test {

    public static void main(String args[]){
         Comparator<PointComparator> OrderDistance =  new Comparator<PointComparator>(){
            public int compare(PointComparator one, PointComparator two) {
                if (one.distance < two.distance)
                    return 1;
                else if (one.distance > two.distance)
                    return -1;
                else
                    return 0;
            }
        };

        //定义一个优先队列,用来排序任意两点之间的距离，从大到小排
        Queue<PointComparator> FsQueue = new PriorityQueue<PointComparator>(10,OrderDistance);

        for (int i=0;i<6;i++){

//            java.util.Random r= new java.util.Random(10);
            point one =new point(i*2+1,i*3+2);
            point two =new point(i*5+2,i*6+3);
            PointComparator nodecomp = new PointComparator(one,two);

//            DecimalFormat df = new DecimalFormat("#.##");
            FsQueue.add(nodecomp);
        }
        DecimalFormat df = new DecimalFormat("#.###");
        for (int i = 0;i<6;i++){
            System.out.println(df.format(FsQueue.poll().distance));
        }
    }

}